package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.entity.BaseAttrInfo;
import com.atguigu.gmall.model.product.entity.BaseAttrValue;
import com.atguigu.gmall.product.service.BaseAttrValueService;
import com.atguigu.gmall.model.product.vo.SaveBaseAttrInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:lyd
 **/
@RestController
@RequestMapping("/admin/product")
public class BaseAttrValueController {


    @Autowired
    BaseAttrValueService baseAttrValueService;

    /**
     * 根据分类id查询平台属性列表
     * @param c1Id
     * @param c2Id
     * @param c3Id
     * @return
     */
    @GetMapping("/attrInfoList/{c1Id}/{c2Id}/{c3Id}")
    public Result attrInfoList(@PathVariable("c1Id") Long c1Id,
                                @PathVariable("c2Id") Long c2Id,
                                @PathVariable("c3Id") Long c3Id){
        List<BaseAttrInfo> list =  baseAttrValueService.attrInfoList(c1Id, c2Id, c3Id);
        return  Result.ok(list);
    }

    /**
     * 保存平台属性
     * @param vo
     * @return
     */
    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody SaveBaseAttrInfoVo vo) {
        baseAttrValueService.saveAttrInfo(vo);
        return Result.ok();
    }

    /**
     * 根据平台属性id查询平台属性值列表
     * @param attrId
     * @return
     */
    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable("attrId") Long attrId) {
        List<BaseAttrValue> list = baseAttrValueService.lambdaQuery()
                .eq(BaseAttrValue::getAttrId, attrId)
                .list();
        return Result.ok(list);
    }

}
